const { defineConfig } = require('@vue/cli-service');
const path = require("path");
const resolve = dir => path.join(__dirname, dir);
// js压缩
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
// gzip
const CompressionWebpackPlugin = require('compression-webpack-plugin');
// 多线程
// const ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin');
// 进度条
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
module.exports = defineConfig({
  publicPath: process.env.NODE_ENV === 'production' ? '/rl-plus/' : '/',
  transpileDependencies: false,
  lintOnSave: false,
  chainWebpack: (config) => {
    // 缓存js
    config.module.rule('js').test(/\.js$/).use().loader('babel-loader?cacheDirectory=true').end()
  },
  configureWebpack: {
    plugins: [
      new UglifyJsPlugin({
        uglifyOptions: {
          compress: {
            drop_debugger: true, // console
            drop_console: true,
            pure_funcs: ['console.log'] // 移除console
          }
        },
        sourceMap: false,
        parallel: true
      }),
      new CompressionWebpackPlugin({
        algorithm: 'gzip',
        test: new RegExp(`\\.(${['js', 'css'].join('|')})$`),
        threshold: 10240
      }),
      // new ParallelUglifyPlugin({ // 多进程压缩
      //   cacheDir: '.cache/',
      //   uglifyJS: {
      //     output: {
      //       comments: false,
      //       beautify: false
      //     },
      //     compress: {
      //       warnings: false,
      //       drop_console: true,
      //       collapse_vars: true,
      //       reduce_vars: true
      //     }
      //   }
      // }),
      // new ParallelUglifyPlugin(),
      new ProgressBarPlugin()
    ]
  }
})
